<template>
    <div>
        <span>倒计时{{ time }}s后重新获取</span>
    </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue';

let time = ref<number>(60)
let props = defineProps(['countdown'])

let $emit = defineEmits(['getCountdown'])

watch(() => props.countdown, () => {
    let timer = setInterval(() => {
        time.value--
        if (time.value == 0) {
            clearInterval(timer)
            $emit('getCountdown', false)
        }
    }, 1000)
}, {
    immediate: true
})
</script>

<style scoped></style>